<!DOCTYPE html>
<html lang="zh-CN"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      layout:decorator="model/boardModel">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link th:href="@{/bootstrap/css/bootstrap-datetimepicker.min.css}" rel="stylesheet" media="screen"/>
    <link rel="stylesheet" th:href="@{/plugins/bootstrap-select/bootstrap-select.min.css}"/>
    <script th:src="@{/plugins/area/CityJson.js}"></script>
    <script th:src="@{/plugins/area/ProJson.js}"></script>
    <script th:src="@{/plugins/area/DistrictJson.js}"></script>


    <title>订单管理</title>
    <style type="text/css">
        .modal-dialog {
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            right: 0;
            right: 0;
        }
        .nav>li>a:hover, .nav>li>a:active, .nav>li>a:focus {
            background: #56c4bf;
        }
    </style>

</head>
<body>

<div th:fragment="pagenav" th:remove="tag">
    <div th:replace="model/nav :: pageheader ('财务管理','客户结算函')"></div>
</div>

<div th:fragment="content" th:remove="tag">


    <div class="row">
        <div class="col-xs-12">

            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">查询条件</h3>
                    <div class="box-tools pull-right">
                        <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                    </div>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <form id="queryForm" method="post">
                    <shiro:hasRole name="sys_nationwide">
                        <div class="box-body">
                            <div class="row">
                                <input type="hidden" name="status" value="600"/>
                                <div class="col-sm-4">
                                    <select id="selProvince"  style="width: 140px;height: 34px;float:left" data-rule-required="true" data-msg-required="请选择省份" class="form-control select2" >
                                        <option value="0">--省份--</option>
                                    </select>
                                    <select id="selCity"  style="width: 140px;height: 34px;float:left" data-rule-required="true" data-msg-required="请选择城市" class="form-control select2" >
                                        <option value="0">--城市--</option>
                                    </select>
                                </div>
                                <div class="col-xs-3">
                                    <select class="selectpicker form-control" data-live-search="true" name="kaId" id="kaId"  data-rule-required="true" data-msg-required="请选择客户">
                                        <option value="9999">选择客户</option>
                                    </select>
                                </div>
                            </div>
                            <br/>
                            <div class="row">
                                <div class="col-xs-3">
                                    <div class="input-group date form_date" data-date="" data-date-format="yyyy-MM" data-link-field="dtp_input2" data-link-format="yyyy-MM">
                                        <input th:name="settleMonth" class="form-control input-sm" type="text" th:value="${month}" id="settleMonth" readonly="readonly" placeholder="结算月份"/>
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                                    </div>
                                </div>
                                <div class="col-xs-3">
                                    <button id="btn-query" type="button" class="btn btn-primary pull-right btn-sm">查询</button>
                                </div>
                            </div>
                        </div>
                    </shiro:hasRole>

                    <shiro:hasRole name="sys_agency">
                        <div class="box-body">
                            <div class="row">
                                <input type="hidden" th:name="status" value="600"/>
                                    <div class="col-sm-3">
                                        <select id="selProvince1" style="width: 100px;height: 34px;float:left"  class="form-control select2" >
                                            <option value="0">--省份--</option>
                                        </select>
                                        <select id="selCity1" style="width: 100px;height: 34px;float:left"  class="form-control select2" >
                                            <option value="0">--城市--</option>
                                        </select>
                                        <input type="hidden" id="proforSearch" name="provinceName"/>
                                        <input type="hidden" id="cityforSearch" name="cityName"/>
                                    </div>
                                <div class="col-xs-3">
                                    <input type="text" th:name="kaName" class="form-control input-sm" placeholder="客户名称"/>
                                </div>
                                <div class="col-xs-3">
                                    <div class="input-group date form_date" data-date="" data-date-format="yyyy-MM" data-link-field="dtp_input2" data-link-format="yyyy-MM">
                                        <input th:name="searchTime" class="form-control input-sm" type="text" th:value="${month}" id="settleMonthA" readonly="readonly" placeholder="结算月份"/>
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                                    </div>
                                </div>
                                <input type="hidden" th:name="agencyId" th:value="${session.authUser.userId}" />
                                <div class="col-xs-3">
                                    <button id="btn-query-agency" type="button" class="btn btn-primary pull-right btn-sm">查询</button>
                                </div>
                            </div>
                        </div>

                    </shiro:hasRole>

                    <shiro:hasRole name="sys_bd">
                        <div class="box-body">
                            <div class="row">
                                <div class="col-xs-3">
                                    <input type="text" th:name="kaName" class="form-control input-sm" placeholder="客户名称"/>
                                </div>
                                <div class="col-xs-3">
                                    <div class="input-group date form_date" data-date="" data-date-format="yyyy-MM" data-link-field="dtp_input2" data-link-format="yyyy-MM">
                                        <input th:name="settleDate" class="form-control input-sm" type="text" th:value="${month}" id="settleMonthA" readonly="readonly" placeholder="结算月份"/>
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                                    </div>
                                </div>
                                <div class="col-xs-3">
                                    <select name="status" class="form-control select2" >
                                        <option value="1">待确认</option>
                                        <option value="2">已确认</option>
                                    </select>
                                </div>
                                <input type="hidden" th:name="cityAgencyId" th:value="${session.authUser.userId}" />
                                <div class="col-xs-3">
                                    <button id="btn-query-bd" type="button" class="btn btn-primary pull-right btn-sm">查询</button>
                                </div>
                            </div>
                        </div>
                    </shiro:hasRole>

                    <!-- /.box-body -->

                    <div class="box-footer">

                    </div>
                </form>
            </div>

            <shiro:hasRole name="sys_nationwide">
                <div class="box">
                    <div class="box-body">
                        <div class="table-responsive">
                        <table id="dataTable" class="table table-striped table-bordered table-hover table-condensed">

                            <thead>
                            <tr>
                                <th>订单编号</th>
                                <th>物品名称</th>
                                <th>旧机款</th>
                                <th>店员服务费</th>
                                <th>店员名称</th>
                                <th>所属门店</th>
                                <th>订单状态</th>
                                <th>下单时间</th>
                            </tr>
                            </thead>


                        </table>
                        </div>
                    </div>
                </div>
            </shiro:hasRole>
            <shiro:hasRole name="sys_agency">
                <div class="box">
                    <div class="box-body">
                        <table id="dataTableAgency" class="table table-striped table-bordered table-hover table-condensed">
                            <thead>
                            <tr>
                                <th>选择</th>
                                <th>省份</th>
                                <th>城市</th>
                                <th>客户名称</th>
                                <th>收款账户</th>
                                <th>收款账户名</th>
                                <th>操作</th>
                            </tr>
                            </thead>

                        </table>
                    </div>
                </div>
            </shiro:hasRole>
            <shiro:hasRole name="sys_bd">
                <div class="box">
                    <div class="box-body">
                        <table id="dataTableDb" class="table table-striped table-bordered table-hover table-condensed">
                            <thead>
                            <tr>
                                <th>省份</th>
                                <th>城市</th>
                                <th>客户名称</th>
                                <th>结算月份</th>
                                <th>备注</th>
                                <th>操作</th>
                            </tr>
                            </thead>

                        </table>
                    </div>
                </div>
            </shiro:hasRole>
        </div>

    </div>

    <form id="exportForm">
        <input type="hidden" th:name="status"/>
        <input type="hidden" th:name="kaId"/>
        <input type="hidden" th:name="settleMonth"/>
    </form>
    <form id="batchForm">

    </form>
    <script type="text/javascript" src="../bootstrap/js/bootstrap-datetimepicker.min.js" charset="UTF-8"></script>
    <script type="text/javascript" src="../bootstrap/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
    <script th:src="@{/plugins/bootstrap-select/bootstrap-select.min.js}"></script>
    <script>

        $(function () {
            var tables = $("#dataTable").dataTable({
                serverSide: true,//分页，取数据等等的都放到服务端去
                processing: true,//载入数据的时候是否显示“载入中”
                pageLength: 10,  //首次加载的数据条数
                ordering: false,//排序操作在服务端进行，所以可以关了。
                pagingType: "full_numbers",
                autoWidth: false,
                stateSave: true,//保持翻页状态，和tables.fnDraw(false);结合使用
                searching: false,
                ajax:{   //类似jquery的ajax参数，基本都可以用。
                    type: "post",//后台指定了方式，默认get，外加datatable默认构造的参数很长，有可能超过get的最大长度。
                    url: "/kas/list",
                    dataSrc: "data",//默认data，也可以写其他的，格式化table的时候取里面的数据
                    data: function (d) {//d是原始的发送给服务器的数据，默认很长。
                        var param = {}; //因为服务端排序，可以新建一个参数对象
                        param.draw = d.draw;
                        param.start = d.start;
                        param.length = d.length;
                        var formData = $("#queryForm").serializeArray();//把form里面的数据序列化成数组
                        formData.forEach(function (e) {
                            param[e.name] = e.value;
                        });
                    return param;//自定义需要传递的参数。
                    }
                },
                columns: [//对应上面thead里面的序列
                    {"data": 'orderNo', defaultContent: ""},
                    {"data": 'goodsName', defaultContent: ""}, //mData 表示发请求时候本列的列明，返回的数据中相同下标名字的数据会填充到这一列
                    {"data": 'amount', defaultContent: ""},
                    {"data": 'clerkCharge', defaultContent: ""},
                    {"data": 'empName', defaultContent: ""},
                    {"data": 'storeName', defaultContent: ""},
                    {"data": 'statusName', defaultContent: ""},
                    {"data": 'createTimeStr', defaultContent: ""}
                ],
                /*<![CDATA[*/
                dom: '<"toolbar">frtip',
                /*]]>*/
                language: {
                    lengthMenu: "",
                    processing: "加载中",//处理页面数据的时候的显示
                    /*<![CDATA[*/
                    paginate: {//分页的样式文本内容。
                        previous: "上一页",
                        next: "下一页",
                        first: "首页",
                        last: "尾页"
                    },
                    /*]]>*/
                    zeroRecords: "没有数据",
                    info: "共 _PAGES_ 页，显示第 _START_ 到第 _END_ 条",
                    infoEmpty: "0条记录",//筛选为空时左下角的显示。0条记录
                    infoFiltered: "",//筛选之后的左下角筛选提示(另一个是分页信息显示，在上面的info中已经设置，所以可以不显示)，
                    sSearch: "关键字："
                }

            });
             var agencyTable =  $("#dataTableAgency").dataTable({
                 serverSide: true,//分页，取数据等等的都放到服务端去
                 processing: true,//载入数据的时候是否显示“载入中”
                 pageLength: 10,  //首次加载的数据条数
                 ordering: false,//排序操作在服务端进行，所以可以关了。
                 pagingType: "full_numbers",
                 autoWidth: false,
                 stateSave: true,//保持翻页状态，和tables.fnDraw(false);结合使用
                 searching: false,
                 ajax:{   //类似jquery的ajax参数，基本都可以用。
                     type: "post",//后台指定了方式，默认get，外加datatable默认构造的参数很长，有可能超过get的最大长度。
                     url: "/batch/list",
                     dataSrc: "data",//默认data，也可以写其他的，格式化table的时候取里面的数据
                     data: function (d) {//d是原始的发送给服务器的数据，默认很长。
                         var param = {}; //因为服务端排序，可以新建一个参数对象
                         param.draw = d.draw;
                         param.start = d.start;
                         param.length = d.length;
                         var formData = $("#queryForm").serializeArray();//把form里面的数据序列化成数组
                         formData.forEach(function (e) {
                             param[e.name] = e.value;
                         });
                         return param;//自定义需要传递的参数。
                     }
                 },
                 columns: [//对应上面thead里面的序列
                     {"data":'kaId',
                         "render":function(data,type,full,callback) {
                             /*<![CDATA[*/
                              return "<input type='checkbox' kaId='"+data+"'/>"
                             /*]]>*/
                         }
                     },
                     {"data": 'provinceName', defaultContent: ""},
                     {"data": 'cityName', defaultContent: ""}, //mData 表示发请求时候本列的列明，返回的数据中相同下标名字的数据会填充到这一列
                     {"data": 'kaName', defaultContent: ""},
                     {"data": 'accountName', defaultContent: ""},
                     {"data": 'accountNumber', defaultContent: ""},
                     {"data": null, "width": "180px"}
                 ],
                 /*<![CDATA[*/
                 columnDefs: [
                     {
                         targets: -1,//编辑
                         data: null,//下面这行，添加了编辑按钮和，删除按钮
                         defaultContent: "<div class='btn-group'><button id='editRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-edit'></i>导出结算函</button>" +
                         "<button id='sendRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-hand-pointer-o'></i>下派结算函</button></div>"
                     }
                 ],
                 dom: '<"toolbar">frtip',
                 /*]]>*/
                 language: {
                     lengthMenu: "",
                     processing: "加载中",//处理页面数据的时候的显示
                     /*<![CDATA[*/
                     paginate: {//分页的样式文本内容。
                         previous: "上一页",
                         next: "下一页",
                         first: "首页",
                         last: "尾页"
                     },
                     /*]]>*/
                     zeroRecords: "没有数据",
                     info: "共 _PAGES_ 页，显示第 _START_ 到第 _END_ 条",
                     infoEmpty: "0条记录",//筛选为空时左下角的显示。0条记录
                     infoFiltered: "",//筛选之后的左下角筛选提示(另一个是分页信息显示，在上面的info中已经设置，所以可以不显示)，
                     sSearch: "关键字："
                 }

             });
             var bdTable = $("#dataTableDb").dataTable({
                 serverSide: true,//分页，取数据等等的都放到服务端去
                 processing: true,//载入数据的时候是否显示“载入中”
                 pageLength: 10,  //首次加载的数据条数
                 ordering: false,//排序操作在服务端进行，所以可以关了。
                 pagingType: "full_numbers",
                 autoWidth: false,
                 stateSave: true,//保持翻页状态，和tables.fnDraw(false);结合使用
                 searching: false,
                 ajax:{   //类似jquery的ajax参数，基本都可以用。
                     type: "post",//后台指定了方式，默认get，外加datatable默认构造的参数很长，有可能超过get的最大长度。
                     url: "/kas/citylist",
                     dataSrc: "data",//默认data，也可以写其他的，格式化table的时候取里面的数据
                     data: function (d) {//d是原始的发送给服务器的数据，默认很长。
                         var param = {}; //因为服务端排序，可以新建一个参数对象
                         param.draw = d.draw;
                         param.start = d.start;
                         param.length = d.length;
                         var formData = $("#queryForm").serializeArray();//把form里面的数据序列化成数组
                         formData.forEach(function (e) {
                             param[e.name] = e.value;
                         });
                         return param;//自定义需要传递的参数。
                     }
                 },
                 columns: [//对应上面thead里面的序列
                     {"data": 'provinceName', defaultContent: ""},
                     {"data": 'cityName', defaultContent: ""}, //mData 表示发请求时候本列的列明，返回的数据中相同下标名字的数据会填充到这一列
                     {"data": 'kaName', defaultContent: ""},
                     {"data": 'settleDate', defaultContent: ""},
                     {"data": 'memo', defaultContent: ""},
                     {"data": 'status', "width": "180px",
                         "render":function(data,type,full,callback) {
                             /*<![CDATA[*/
                             if(data==1) return "<div class='btn-group'><button id='loadRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-edit'></i>查看结算函</button>" +
                                 "<div class='btn-group'><button id='successRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-hand-pointer-o'></i>结算完成</button>";
                             else return "<div class='btn-group'><button id='loadRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-edit'></i>查看结算函</button>";
                             /*]]>*/
                         }
                     }
                 ],
                 /*<![CDATA[*/
                 dom: '<"toolbar">frtip',
                 /*]]>*/
                 language: {
                     lengthMenu: "",
                     processing: "加载中",//处理页面数据的时候的显示
                     /*<![CDATA[*/
                     paginate: {//分页的样式文本内容。
                         previous: "上一页",
                         next: "下一页",
                         first: "首页",
                         last: "尾页"
                     },
                     /*]]>*/
                     zeroRecords: "没有数据",
                     info: "共 _PAGES_ 页，显示第 _START_ 到第 _END_ 条",
                     infoEmpty: "0条记录",//筛选为空时左下角的显示。0条记录
                     infoFiltered: "",//筛选之后的左下角筛选提示(另一个是分页信息显示，在上面的info中已经设置，所以可以不显示)，
                     sSearch: "关键字："
                 }

             });
            /*<![CDATA[*/
                $.each(province, function (k, p) {
                    var option = "<option value='" + p.ProID + "'>" + p.ProName + "</option>";
                    $("#selProvince").append(option);
                    $("#selProvince1").append(option);
                });
                $("#selProvince").change(function () {
                    var selValue = $(this).val();
                    $("#selCity option:gt(0)").remove();
                    $.each(city, function (k, p) {
                        if (p.ProID == selValue) {
                            var option = "<option value='" + p.CityID + "'>" + p.CityName + "</option>";
                            $("#selCity").append(option);
                        }
                    });

                });
            $("#selProvince1").change(function () {
                var selValue = $(this).val();
                $("#selCity1 option:gt(0)").remove();
                $.each(city, function (k, p) {
                    if (p.ProID == selValue) {
                        var option = "<option value='" + p.CityID + "'>" + p.CityName + "</option>";
                        $("#selCity1").append(option);
                    }
                });

            });
                $("#selCity").change(function () {
                    var selValue = $(this).val();
                    $("#kaId > option").remove();
                    $('#kaId').selectpicker('refresh');
                    $('#kaId').selectpicker('render');

                    $.ajax({
                        url: '/store/getkaList',
                        type: 'POST',
                        dataType: "json",
                        data:{"cityId":selValue},
                        cache: "false",
                        success: function (result) {
                            if (result.result == 200) {
                                $.each(result.data, function (i, n) {
                                    $("#kaId").append("<option value='" + n.kaId + "'>" + n.kaName + "</option>")

                                    $('#kaId').selectpicker('refresh');
                                    $('#kaId').selectpicker('render');
                                });
                            }
                        },
                        error:function(err){
                            toastr.error("网络错误...");
                        }
                    });
                });
            /*]]>*/
            <shiro:hasRole name="sys_nationwide">
            $("div.toolbar").html('<button type="button" class="btn btn-primary btn-sm" id="btn-down">导出excel</button>')
            </shiro:hasRole>

            <shiro:hasRole name="sys_agency">
                $("div.toolbar").html('<button type="button" class="btn btn-primary btn-sm" id="btn-batch">批量下派</button>&nbsp;&nbsp;&nbsp;&nbsp;' +
                    '<button type="button" class="btn btn-primary btn-sm" id="btn-exports">批量导出</button><br/>')
             </shiro:hasRole>
            $("#btn-query-agency").on("click",function () {
                if($("#selProvince1").val()!=0){
                    $("#proforSearch").val($("#selProvince1").find("option:selected").text())
                }
                if($("#selCity1").val()!=0){
                    $("#cityforSearch").val($("#selCity1").find("option:selected").text())
                }
                agencyTable.fnDraw();
            })
            $("#btn-query-bd").on("click",function () {
                bdTable.fnDraw();
            })
            //下载结算函
            $("#dataTableDb tbody").on("click","#loadRow",function () {
                var data = bdTable.api().row($(this).parents("tr")).data();
                /*<![CDATA[*/
                window.location.href ="/sysUpload/download?fileUrl="+data.fileUrl+"&fileName="+data.memo+".xls";
                /*]]>*/
            })
            //结算完成
            $("#dataTableDb tbody").on("click","#successRow",function () {
                var data = bdTable.api().row($(this).parents("tr")).data();
                var obj = $(this);
                obj.attr("disabled",true);
                $.ajax({
                    url: '/kas/settleDone',
                    type: 'POST',
                    dataType: "json",
                    data:{"id":data.id,"status":2},
                    cache: "false",
                    success: function (result) {
                        if (result.result == 200) {
                            toastr.success(result.msg);
                            obj.attr("disabled",false);
                            bdTable.fnDraw();
                        } else {
                            toastr.error(result.msg);
                            obj.attr("disabled",false);
                        }
                    },
                    error: function (err) {
                        toastr.error("网络错误...");
                        obj.attr("disabled",false);
                    }
                });
            })
            //省总的导出
            $("#dataTableAgency tbody").on("click","#editRow",function () {
                $("#exportForm input[name=status]").val("");
                $("#exportForm input[name=kaId]").val("");
                var data = agencyTable.api().row($(this).parents("tr")).data();
                $("#exportForm input[name=status]").val("600");
                $("#exportForm input[name=kaId]").val(data.kaId);
                $("#exportForm input[name=settleMonth]").val($("#settleMonthA").val());
                $("#exportForm").attr("target","");
                $("#exportForm").attr('action','/kas/export');
                $("#exportForm").submit();
            })
            //下派结算函
            $("#dataTableAgency tbody").on("click","#sendRow",function () {
                var obj = $(this);
                obj.attr("disabled",true);
                $("#exportForm input[name=status]").val("");
                $("#exportForm input[name=kaId]").val("");
                var data = agencyTable.api().row($(this).parents("tr")).data();
                $("#exportForm input[name=status]").val("600");
                $("#exportForm input[name=kaId]").val(data.kaId);
                $("#exportForm input[name=settleMonth]").val($("#settleMonthA").val());
                $.ajax({
                    url: '/kas/sendToCity',
                    type: 'POST',
                    dataType: "json",
                    data:$("#exportForm").serialize(),
                    cache: "false",
                    success: function (result) {
                        if (result.result == 200) {
                            toastr.success(result.msg);
                            obj.attr("disabled",false);
                        } else {
                            toastr.error(result.msg);
                            obj.attr("disabled",false);
                        }
                    },
                    error: function (err) {
                        toastr.error("网络错误...");
                        obj.attr("disabled",false);
                    }
                });
            })
            //查询按钮
            $("#btn-query").on("click", function () {
                var valdata = $("#queryForm").validate();
                tables.fnDraw();
            });

            //导出按钮
            $("#btn-down").on("click", function () {
                if($("#selProvince").val()==0){
                    alert("请选择省份");
                    return
                }
                if($("#selCity").val()==0){
                    alert("请选择城市");
                    return
                }

                if(!$("#kaId").val() || $("#kaId").val()=='9999'){
                    alert("请选择客户");
                    return
                }
                if(!$("#settleMonth").val()){
                    alert("请选择结算月份");
                    return
                }
                var form = $("#queryForm");
                form.attr('target','');
                form.attr('action','/kas/export');
                form.submit();
            });
            //批量下派
            $("#btn-batch").on("click",function () {
                $("#btn-batch").attr("disabled",true);
                var temp = 0;
                var settleMonth = $("#settleMonthA").val();
                if($("#dataTableAgency input[type=checkbox]:checked").length==0){
                    toastr.error("请选择要下派的结算函");
                    $("#btn-batch").attr("disabled",false);
                    return
                }
                $("#dataTableAgency input[type=checkbox]:checked").each(function () {
                    var kaId = $(this).attr("kaId");
                    /*<![CDATA[*/
                    $("#batchForm").append("<input type='hidden' name='orders["+temp+"].status' value='600'/>" +
                        "<input type='hidden'name='orders["+temp+"].kaId' value='"+kaId+"'/>" +
                        "<input type='hidden' name='orders["+temp+"].settleMonth' value='"+settleMonth+"'/>")
                    temp++;
                    /*]]>*/
                })
                $.ajax({
                    url: '/kas/sendToCitybatch',
                    type: 'POST',
                    dataType: "json",
                    data:$("#batchForm").serialize(),
                    cache: "false",
                    success: function (result) {
                        if (result.result == 200) {
                            toastr.success(result.msg);
                            agencyTable.fnDraw();
                            $("#btn-batch").attr("disabled",false);
                        } else {
                            toastr.error(result.msg);
                            $("#btn-batch").attr("disabled",false);
                        }
                    },
                    error: function (err) {
                        toastr.error("网络错误...");
                        $("#btn-batch").attr("disabled",false);
                    }
                });
            })
            //批量导出
            $("#btn-exports").on("click",function () {
                if($("#selProvince1").val()==0){
                    alert("请选择省份");
                    return
                }
                if($("#selCity1").val()==0){
                    alert("请选择城市");
                    return
                }
                /*<![CDATA[*/
                $("div.toolbar button").hide();
                $("div.toolbar").append("<div class='progress active' style='width: 500px;height: 25px;'><div class='progress-bar progress-bar-primary progress-bar-striped' id='progress-bar'" +
                    " role='progressbar' aria-valuenow='10' aria-valuemin='0' aria-valuemax='100' style='width: 10%'>导出中...</div></div>")
                /*]]>*/
                $("#proforSearch").val($("#selProvince1").find("option:selected").text())
                $("#cityforSearch").val($("#selCity1").find("option:selected").text())

                var form = $("#queryForm");
                form.attr('target','');
                form.attr('action','/kas/exports');
                form.submit();
                var timer =  setInterval(function () {
                    $.ajax({
                        url: '/kas/isExports',
                        type: 'POST',
                        dataType: "json",
                        cache: "false",
                        success: function (result) {
                            if (result.result == 200) {
                                /*<![CDATA[*/
                                var now = parseInt($("#progress-bar").attr("aria-valuenow")) +20;
                                if(now < 121){
                                    $("#progress-bar").attr("aria-valuenow",now);
                                    $("#progress-bar").attr("style","width:"+now+"%");
                                }
                                /*]]>*/
                            }else{
                                /*<![CDATA[*/
                                $("div.toolbar button").show();
                                $("div.toolbar div ").remove();
                                /*]]>*/
                                clearInterval(timer);
                            }
                        }
                    })
                },"1000");
            })

        })


        //时间插件
        $('.form_date').datetimepicker({
            format: 'yyyy-mm',
            autoclose: true,
            todayBtn: true,
            startView: 'year',
            minView:'year',
            maxView:'decade',
            language:  'zh-CN',
            startDate:'2017-06',
            endDate:new Date()
        });
    </script>


</div>


</body>
</html>
